#include "Teacher.h"
#include<stdio.h>
#include<string.h>

void InitTeacher(Teach *t,const char * name,int age)
{
   strcpy(t->Name,name);
   t->age=age;
   t->size=0;
}

void PrintTeacher(Teach *t)
{
    printf("Name=%s,age=%d\n",t->Name,t->age);
    for(int i=0;i<t->size;i++)
    {
        PrintStu(t->s+i);
    }
}

void InsertStu(Teach *t, const char *name, int id, int age, double score)
{
    SetStuValue(&t->s[t->size],name,id,age,score);
    t->size++;
}

void RemoveByIndex(Teach *t,int index)
{
    for(int i=index;i<t->size-1;i++)
    {
        t->s[i]=t->s[i+1];
    }
    t->size--;
}

void RemoveStu(Teach *t,const char *name)
{
    for(int i=0;i<t->size;i++)
    {
        if(strcmp(t->s[i].Name,name)==0)
        {
          RemoveByIndex(t,i);
          i--;
        }
        
    }
}

Stu *FindFirstStu(Teach *t, void *value,bool(*p)(Stu*,void*))
{
    for(int i=0;i<t->size;i++)
    {
        //符合条件
        if(p(&t->s[i],value)==true)
        return &t->s[i];
    }
    return NULL;
}
